﻿var addressid; var deliverid; var payid; var deliverinfo; var sendid;
var addressobject = null; var deliveobject = null; var payobject = null;


$(function () {
	var _id = $(".uladdress li").attr("data-id");

	//选择地址
	$(".uladdress li").live("click", function () {
		var delive = $(this).attr("delive-data")
		addressid = $(this).attr("data-id")
		$(".uladdress li").each(function () {
			$(this).attr("class", "");
		});
		$(this).attr("class", "sel");
		addressobject = this;
		createDeliver(delive);

	})
	//选择配送方式；
	$(".uldelive dd").live("click", function () {
		deliverid = $(this).attr("map");
		$(".uldelive dd").each(function () {
			$(this).attr("class", "");
		});
		$(this).attr("class", "sel");
		deliveobject = this;
		var m = $(this).attr("map").split("|");
		if (m[3] == 0) {
			$('#pay-3').fadeOut('slow');
		}
		else {
			$('#pay-3').fadeIn('slow');
		}
		$("#pay-1").trigger("click");
		payid = "1";
		sendid = $(this).attr("data-id");
		$("#DeliverPrice").html(deliverid.split("|")[2])
	});

	//选择支付方式
	$(".ulpay dd").live("click", function () {
		$(".ulpay dd").each(function () {
			$(this).attr("class", "");
		});
		$(this).attr("class", "sel");
		payid = $(this).attr("data-id");
	});
	$("#ul-" + _id).trigger("click");

	$("#getInvoice").click(function () {
		if ($("#invoiceTxt").css("display") == "none") {
			$("#invoiceTxt").fadeIn('slow');
		}
		else { $("#invoiceTxt").fadeOut('slow'); }
	});
	$("#saveorder").click(function () {
		$('#basic-modal-content').modal()
		this.disabled = "disabled";
		var Invoice = $("#Invoice").val()
		$.post("/MyKunlun/CreateOrder", { "addressid": addressid, "sendid": sendid, "payid": payid, "invoice": Invoice },
            function (data) {
                window.open("/MyKunlun/OrderPayAction/" + data);
            });
	});
});
//修改配送方式
function createDeliver(deliver) {
	deliverid = "";
	var d = deliver.split(",");
	for (i = 0; i < d.length; i++) {
		var m = d[i].split("|");
		$('#deliver-' + m[0]).removeAttr("map");
		$('#deliver-' + m[0]).attr("map", d[i]);
		if (m[1] == 0) {
			$('#deliver-' + m[0]).fadeOut('slow');
		}
		else {
			$('#deliver-' + m[0]).fadeIn('slow');
			//设置默认配送方式
			if (deliverid == "") {
				$("#deliver-" + m[0]).trigger("click");
			}
		}
	}
}